﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace XbdSoft.Controls
{
    public class XbdTreeView:System.Windows.Forms.TreeView
    {
        public XbdTreeView()
        {
            //DrawMode = System.Windows.Forms.TreeViewDrawMode.OwnerDrawAll;
        }

      
        protected override void OnDrawNode(System.Windows.Forms.DrawTreeNodeEventArgs e)
        {
            if (e.Node.IsSelected)
            {
                e.Node.BackColor = Color.LightBlue;
            }
            else
            {
                e.Node.BackColor = Color.Transparent;
            }
            base.OnDrawNode(e);
        }

        private TreeNode lastMouseHoverNode = null;
        protected override void OnNodeMouseHover(System.Windows.Forms.TreeNodeMouseHoverEventArgs e)
        {
            if (lastMouseHoverNode != null)
            {
                lastMouseHoverNode.BackColor = Color.Transparent;
            }
            if (!e.Node.IsSelected)
            {
                e.Node.BackColor = Color.AliceBlue;
            }
            else
            {
                e.Node.BackColor = Color.LightBlue;
            }
            lastMouseHoverNode = e.Node;
            base.OnNodeMouseHover(e);
        }

        protected override void OnLostFocus(EventArgs e)
        { 
            base.OnLostFocus(e);
        }

        protected override void OnAfterExpand(TreeViewEventArgs e)
        {
            base.OnAfterExpand(e);
            ShowPlusMinus = false;
        }
        protected override void OnAfterCollapse(TreeViewEventArgs e)
        {
            base.OnAfterCollapse(e);
            ShowPlusMinus = true;
        }
    }
}
